package priv.userdefinedexplainwithnotes;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;

/*
 * 作者：m鹏h
 * 时间；2024/7/31 23:21
 * 描述：获取自定义注解定义的值
 **/
public class GetValus {
 public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
  Class aClass = Class.forName("priv.userdefinedexplainwithnotes.MphTest");
  Annotation[] annotations = aClass.getAnnotations();
  for (Annotation annotation : annotations) {
   System.out.println("类注解："+annotation);
   mph mph = (mph) annotation;
    System.out.println("定义注解的作者："+mph.value());
  }
  Field set = aClass.getDeclaredField("sex");
  sex set1 = set.getDeclaredAnnotation(sex.class);
  String value = set1.value();
  System.out.println("作者的性别："+value);
  System.out.println("-------------------------------------");
  Field age = aClass.getDeclaredField("age");
  age age1 = age.getDeclaredAnnotation(age.class);
  int value1 = age1.value();
  System.out.println("作者的年龄："+value1);

 }
}
